//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    bottomViewHeight:"0px;",
    boxShadow:"box-shadow:-1px 0px 1px 1px #dbdbdb;",
    open:true,
    openUserInteractionEnabled:true,
    closeUserInteractionEnabled: false,
    openDataArray: [
      { "index": "1", "icon": "/image/雷达.svg", "title": "潜客雷达", "des": "全网数据建模，锁定目标客群" },
      { "index": "2", "icon": "/image/客流统计.svg", "title": "客流感知", "des": "感知客流实况，掌握售场动态" },
      { "index": "3", "icon": "/image/客群.svg", "title": "客群定位", "des": "洞察客群特征，读懂客户行为" }
    ],
    closeDataArray: [
      { "index": "4", "icon": "/image/广告.svg", "title": "线上定投", "des": "瞄准目标客群，定向投放广告" },
      { "index": "5", "icon": "/image/人群.svg", "title": "线下直击", "des": "海量线下地推，直面目标客群" },
      { "index": "6", "icon": "/image/电话.svg", "title": "精准获客", "des": "直联目标客群，获取有效客户" }
    ],
    openAnimation: wx.createAnimation({
      duration: app.animationTime
    }),
    closeAnimation: wx.createAnimation({
      duration: app.animationTime
    }).scale(0.85, 0.85).translate(40).width("40%").opacity(0.3).step(),
    openDesAnimation: wx.createAnimation({
      duration: app.animationTime
    }),
    closeDesAnimation: wx.createAnimation({
      duration: app.animationTime
    }).opacity(0).step(),
    switchItemAnimation:wx.createAnimation({
      duration: app.animationTime
    }).translateX(0).step(),
    switchUpViewAnimation: wx.createAnimation({
      duration: app.animationTime
    }),
  },
  onLoad: function () {
  // 先做一下移动动画，不然overflow会失效
    this.data.switchUpViewAnimation = wx.createAnimation({
      duration: app.animationTime
    }).translateX(0).step().export();
    this.setData(this.data);

// 获取一下页面剩下的空间
    const query = wx.createSelectorQuery();
    query.select('.topView').boundingClientRect();
    query.exec((rect) => {
      if (wx.canIUse("getSystemInfo.success.windowHeight")) {
        wx.getSystemInfo({
          success: (res) => {
            this.data.bottomViewHeight = res.windowHeight-rect[0].height + "px;";
            this.setData(this.data);
          }
        });
      }
    });
  },
  //switch切换
  clickSwitch:function(){
    this.data.open = !this.data.open;
    if(!this.data.open){
      this.data.openAnimation = wx.createAnimation({
        duration: app.animationTime
      }).scale(0.85, 0.85).translate(-40).opacity(0.3).step().export();
      this.data.closeAnimation = wx.createAnimation({
        duration: app.animationTime
      }).scale(1, 1).translate(0).opacity(1).step().export();
      this.data.openDesAnimation = wx.createAnimation({
        duration: app.animationTime
      }).opacity(0).step().export();
      this.data.closeDesAnimation = wx.createAnimation({
        duration: app.animationTime
      }).opacity(1).step().export();
      this.data.openUserInteractionEnabled = false;
      this.data.closeUserInteractionEnabled = true;
      this.data.switchItemAnimation = wx.createAnimation({
        duration: app.animationTime
      }).translateX(80).step().export();
      this.data.boxShadow = "box-shadow:1px 0px 1px 1px #dbdbdb;";
      this.data.switchUpViewAnimation = wx.createAnimation({
        duration: app.animationTime
      }).translateX(-80).step().export();
    }else{
      this.data.openAnimation = wx.createAnimation({
        duration: app.animationTime
      }).scale(1, 1).translate(0).opacity(1).step().export();
      this.data.closeAnimation = wx.createAnimation({
        duration: app.animationTime
      }).scale(0.85, 0.85).translate(40).width("40%").opacity(0.3).step().export();
      this.data.openDesAnimation = wx.createAnimation({
        duration: app.animationTime
      }).opacity(1).step().export();
      this.data.closeDesAnimation = wx.createAnimation({
        duration: app.animationTime
      }).opacity(0).step().export();
      this.data.openUserInteractionEnabled = true;
      this.data.closeUserInteractionEnabled = false;
      this.data.switchItemAnimation = wx.createAnimation({
        duration: app.animationTime
      }).translateX(0).step().export();
      this.data.boxShadow = "box-shadow:-1px 0px 1px 1px #dbdbdb;";
      this.data.switchUpViewAnimation = wx.createAnimation({
        duration: app.animationTime
      }).translateX(0).step().export();
    }
    this.setData(this.data)
  },
  //功能item点击
  clickTapItem:function(e){
    var targetId = e.currentTarget.dataset.id;
    switch (targetId){
      case "1":{
        if(this.data.openUserInteractionEnabled){
          console.log("点击了");
        }else{
          console.log("失效了");
        }
      }
      break;
      case "2": {
        if (this.data.openUserInteractionEnabled) {
          console.log("点击了");
        } else {
          console.log("失效了");
        }
      }
        break;
      case "3": {
        if (this.data.openUserInteractionEnabled) {
          console.log("点击了");
        } else {
          console.log("失效了");
        }
      }
        break;
      case "4":{
          if (this.data.closeUserInteractionEnabled) {
            console.log("点击了");
          } else {
            console.log("失效了");
          }
        }
      break;
      case "5": {
        if (this.data.closeUserInteractionEnabled) {
          console.log("点击了");
        } else {
          console.log("失效了");
        }
      }
        break;
      case "6": {
        if (this.data.closeUserInteractionEnabled) {
          console.log("点击了");
        } else {
          console.log("失效了");
        }
      }
        break;
      default:
        console.log("没有此id");
    }
  }
})

